/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.xml.handler;

import bbd.crawler.xml.handler.fwk.BaseXMLHandler;

import org.xml.sax.Attributes;

/**
 *
 * @author Amogh
 */
public class WikipediaHandler extends BaseXMLHandler {

    private static final String TAG_REV = "rev";

    private String parsedData = null;

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public WikipediaHandler () {
        setProcessorAvailable ( this.getClass().getName() );
    } // end default constructor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void startElement ( 
                    String uri,
                    String localName,
                    String qName,
                    Attributes attributes)
    {
        if ( TAG_REV.equalsIgnoreCase ( qName ) ) {

            parsedData = new String ("");
        }
        
    } // end of startElement

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void characters (
                    char[] ch,
                    int start,
                    int length)
    {
        StringBuffer data = new StringBuffer ();

        for ( int i = start; i < (start + length); i++ ) {

            data.append ( ch [i] );
        }

        parsedData = parsedData.concat ( data.toString() );

    } // end of characters

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void endElement (
                    String uri,
                    String localName,
                    String qName)
    {
        if ( TAG_REV.equalsIgnoreCase ( qName ) ) {

            dataLoaded = true;
        }

    } // end of endElement

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public Object getParsedData () {
        return parsedData;
    } // end function getParsedData

} // end class WikipediaHandler
